Aerodynamics: Stream Functions & Potential Functions

$$\text{This is a tutorial to help with some visualizations in Aerodynamics (especially with stream functions & potential functions).}$$$$Author:~ Prakash~Vedula$$$$Date:~ 10/19/2018$$
from __future__ import print_function
import pandas as pd
import numpy as np
import matplotlib.ticker as ticker
from mpl_toolkits.mplot3d import Axes3D
import pandas as pd
from scipy.interpolate import griddata
from matplotlib.ticker import LinearLocator, FormatStrFormatter
%matplotlib inline
import matplotlib
import numpy as np
import matplotlib.cm as cm
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt

import matplotlib.pyplot as plt
from ipywidgets import interact, interactive, fixed, interact_manual
import ipywidgets as widgets
matplotlib.rcParams['xtick.direction'] = 'out'
matplotlib.rcParams['ytick.direction'] = 'out'

# Set range
xr = 10
xl = -xr

yu = 10
yl = -yu
# Set x, y  points
npoints = 100
x = np.linspace(xl, xr, npoints)
y = np.linspace(yl, yu, npoints)

X, Y = np.meshgrid(x, y)
$$\text{Some useful conversions:}\\$$$$r = x / cos\theta$$


$$r = y / sin\theta$$
$$r = \sqrt{x^2+y^2}$$
$$\theta = tan^{-1}(y/x)$$ $$\theta = sin^{-1}(y/r)$$ $$\theta = cos^{-1}(x/r)$$

 
$$\text{Uniform Flow}$$$$\Psi = V_\infty x$$$$\Phi = V_\infty y$$
# Uniform Flow

# Set freestream velocity
Vinf = 1 # (units: m/s)
plt.rcParams["figure.figsize"] = (18,9)

plt.subplot(1,2,1)
Z = Vinf * Y
CS = plt.contour(X, Y, Z)

plt.clabel(CS, inline=1, fontsize=11)
plt.title('$\Psi=C$')
plt.xlabel('x')
plt.ylabel('y')


plt.subplot(1,2,2)
Z = Vinf * X
CS = plt.contour(X, Y, Z,linestyles='dashed',cmap='jet')
plt.clabel(CS, inline=1, fontsize=11)

plt.title('$\Phi=C*$')
plt.xlabel('x')
plt.ylabel('y')




plt.savefig('uniformPsiPhi.png')
plt.tight_layout()
plt.show()
# Make data.
 # Set range
plt.rcParams["figure.figsize"] = (20,8)
xr = 10
xl = -xr
yu = 10
yl = -yu

# Set x, y  points
npoints = 100
x = np.linspace(xl, xr, npoints)
y = np.linspace(yl, yu, npoints)
X, Y = np.meshgrid(x, y) 

Vinf = 1
Z = Vinf * Y
Z2 = Vinf * X

fig = plt.figure()
ax = fig.add_subplot(121, projection='3d')
surf = ax.plot_surface(X, Y, Z, cmap=cm.jet)
plt.title(r'$\Psi=C$')
plt.xlabel('x')
plt.ylabel('y')

ax = fig.add_subplot(122, projection='3d')
surf = ax.plot_surface(X, Y, Z2, rstride=1, cstride=1, cmap=cm.jet)
plt.title(r'$\Phi = C^*$')
plt.xlabel('x')
plt.ylabel('y')
ax.view_init(30, 140)
plt.show()
# Uniform Flow interactive chart


def uniformPlot(C, C_star):
    # Set freestream velocity
    Vinf = 1 # (units: m/s)
    plt.rcParams["figure.figsize"] = (10,8)
    # Set range
    xr = 10
    xl = -xr
    yu = 10
    yl = -yu
    
    # Set x, y  points
    npoints = 100
    x = np.linspace(xl, xr, npoints)
    y = np.linspace(yl, yu, npoints)
    X, Y = np.meshgrid(x, y)    
    
    Z = Vinf * Y
    CS = plt.contour(X, Y, Z,levels=[C])
    Z = Vinf * X
    CS2 = plt.contour(X, Y, Z,levels=[C_star], colors='k',linestyles='dashed')
    plt.clabel(CS2, inline=1, fontsize=11)
    linestyles = ['-', '--']
    plt.clabel(CS, inline=1, fontsize=11)
    plt.title(r'$\Psi=C$  and  $\Phi = C^*$')
    plt.xlabel('x')
    plt.ylabel('y')
    plt.tight_layout()
    plt.show()
    
interactive_plot = interactive(uniformPlot, C=widgets.FloatSlider(value=2,min=-9,max=9,step=1,description='$C$'), C_star=widgets.FloatSlider(value=2,min=-9,max=9,step=1,description='$C^*$'));
interactive_plot.children[0].layout.height = '30px'
interactive_plot.children[0].layout.width = '500px'
interactive_plot.children[1].layout.height = '30px'
interactive_plot.children[1].layout.width = '500px'
interactive_plot
 
$$\text{Source Flow}$$$$\Psi = \frac{\Lambda}{2 \pi} \theta\\$$$$\Phi = \frac{\Lambda}{2 \pi} \ln r $$
# Source Flow

# Set freestream velocity
#Lambda = 2 * np.pi #  Set for convenience

Lambda = 0.01

plt.rcParams["figure.figsize"] = (18,9)

plt.subplot(1,2,1)
Z = (Lambda)/(2 * np.pi) * np.arctan(Y/X)
#Z=(Lambda)/(2 * np.pi) * np.arctan2(Y,X)
levels = np.linspace(np.min(Z),0.0035,11)
CS = plt.contour(X, Y, Z)
plt.clabel(CS, inline=1, fontsize=11)
#plt.axis('equal','box')
#plt.title('Simplest default with labels')
plt.title(r'$\Psi =\frac{\Lambda}{2 \pi}\theta$')
plt.xlabel('$x$')
plt.ylabel('$y$')

plt.subplot(1,2,2)
Z = (Lambda)/(2 * np.pi) * np.log( np.sqrt(np.power(X,2) + np.power(Y,2)) )

#plt.contour(Z,np.linspace(Z.min(),Z.max(),15))
levels = np.linspace(np.min(Z),0.0035,11)


CS = plt.contour(X, Y, Z, levels=levels)
#CS = plt.contour(X, Y, Z)
plt.clabel(CS, inline=1, fontsize=11)


plt.title(r'$\Phi = \frac{\Lambda}{2 \pi} \ln r $')
plt.xlabel('$x$')
plt.ylabel('$y$')

plt.tight_layout()
plt.show
<function matplotlib.pyplot.show(*args, **kw)>
# Make data.
 # Set range
plt.rcParams["figure.figsize"] = (20,8)
xr = 10
xl = -xr
yu = 10
yl = -yu

# Set x, y  points
npoints = 100
x = np.linspace(xl, xr, npoints)
y = np.linspace(yl, yu, npoints)
X, Y = np.meshgrid(x, y) 

Vinf = 1
Lambda = 0.01
Z = (Lambda)/(2 * np.pi) * np.arctan(Y/X)
Z2 = (Lambda)/(2 * np.pi) * np.log( np.sqrt(np.power(X,2) + np.power(Y,2)) )

fig = plt.figure()
ax = fig.add_subplot(121, projection='3d')
surf = ax.plot_surface(X, Y, Z, cmap=cm.jet)
plt.title(r'$\Psi =\frac{\Lambda}{2 \pi}\theta$')
plt.xlabel('x')
plt.ylabel('y')
ax.view_init(90, 0)

ax = fig.add_subplot(122, projection='3d')
surf = ax.plot_surface(X, Y, Z2, rstride=1, cstride=1, cmap=cm.jet)
plt.title(r'$\Phi = \frac{\Lambda}{2 \pi} \ln r $')
plt.xlabel('x')
plt.ylabel('y')
ax.view_init(35, 140)
plt.show()
# Source Flow interactive chart

def sourcePlot(C, C2, Lambda):
    # Set freestream velocity
    Vinf = 1 # (units: m/s)
    plt.rcParams["figure.figsize"] = (10,8)
    # Set range
    xr = 10
    xl = -xr
    yu = 10
    yl = -yu
    
    #Lambda = 0.05
    
    # Set x, y  points
    npoints = 100
    x = np.linspace(xl, xr, npoints)
    y = np.linspace(yl, yu, npoints)
    X, Y = np.meshgrid(x, y)
    
    
    Z = (Lambda)/(2 * np.pi) * np.arctan(Y/X)
    #Z=(Lambda)/(2 * np.pi) * np.arctan2(Y,X)
    CS = plt.contour(X, Y, Z, levels=[C])
    plt.clabel(CS, inline=1, fontsize=11)

    Z = (Lambda)/(2 * np.pi) * np.log( np.sqrt(np.power(X,2) + np.power(Y,2)) )
    CS2 = plt.contour(X, Y, Z, levels=[C2], colors='k',linestyles='dashed')
    plt.clabel(CS2, inline=1, fontsize=11)
    
    plt.title(r'$\Psi =\frac{\Lambda}{2 \pi}\theta$ and $\Phi = \frac{\Lambda}{2 \pi} \ln r $')
    plt.xlabel('x')
    plt.ylabel('y')
    plt.tight_layout()
    plt.show()
    
interactive_plot = interactive(sourcePlot, C=widgets.FloatSlider(value=0.001,min=-0.01,max=0.01,step=0.00025,description='$\Psi$'), C2=widgets.FloatSlider(value=0.005,min=-0.01,max=0.01,step=0.00025,description='$\Phi$'), Lambda=widgets.FloatSlider(value=0.03,min=0.01,max=0.1,step=0.01,description='$\Lambda$'));
interactive_plot.children[0].layout.height = '30px'
interactive_plot.children[0].layout.width = '500px'
interactive_plot.children[0].readout_format = '.4f'
interactive_plot.children[1].layout.height = '30px'
interactive_plot.children[1].layout.width = '500px'
interactive_plot.children[1].readout_format = '.4f'
interactive_plot.children[2].layout.height = '30px'
interactive_plot.children[2].layout.width = '500px'
interactive_plot.children[2].readout_format = '.4f'
interactive_plot
#print(interactive_plot.children[1].keys)
 
$$\text{Vortex Flow}$$$$\Psi = \frac{\Gamma}{2 \pi} \ln r \\$$$$\Phi = -\frac{\Gamma}{2 \pi} \theta$$
# Vortex Flow

# Set freestream velocity
#Gamma = 2 * np.pi #  Set for convenience

Gamma = 0.01

plt.rcParams["figure.figsize"] = (18,9)


plt.subplot(1,2,1)
Z = (Gamma)/(2 * np.pi) * np.log( np.sqrt(np.power(X,2) + np.power(Y,2)) )


#CS = plt.contour(X, Y, Z)
levels = np.linspace(np.min(Z),np.max(Z)/1.125,11)
levels = np.linspace(np.min(Z),0.0035,11)


CS = plt.contour(X, Y, Z, levels=levels)
fmt='%1.4f'
plt.clabel(CS, inline=1, fontsize=11,fmt=fmt)
plt.title(r'$\Psi = \frac{\Gamma}{2 \pi} \ln r$')
plt.xlabel('$x$')
plt.ylabel('$y$')


plt.subplot(1,2,2)
#Z = (Lambda)/(2 * np.pi) * np.log( np.power(X,2) + np.power(Y,2) )
Z = -(Gamma)/(2 * np.pi) * np.arctan(Y/X)

#plt.contour(Z,np.linspace(Z.min(),Z.max(),15))
levels = np.linspace(np.min(Z),np.max(Z),11)
CS = plt.contour(X, Y, Z, levels=levels)
#fmt = matplotlib.ticker.EngFormatter()
plt.clabel(CS, inline=1, fontsize=11, fmt=fmt)
#plt.clabel(CS, inline=1, fontsize=11)



#plt.axis('equal','box')
#plt.title('Simplest default with labels')
plt.title(r'$\Phi = -\frac{\Gamma}{2 \pi} \theta$')
plt.xlabel('$x$')
plt.ylabel('$y$')

plt.tight_layout()
plt.show
<function matplotlib.pyplot.show(*args, **kw)>
# Make data.
 # Set range
plt.rcParams["figure.figsize"] = (20,8)
xr = 10
xl = -xr
yu = 10
yl = -yu

# Set x, y  points
npoints = 100
x = np.linspace(xl, xr, npoints)
y = np.linspace(yl, yu, npoints)
X, Y = np.meshgrid(x, y) 

Vinf = 1
Gamma = 0.01
Z = (Gamma)/(2 * np.pi) * np.log( np.sqrt(np.power(X,2) + np.power(Y,2)) )
Z2 = -(Gamma)/(2 * np.pi) * np.arctan(Y/X)

fig = plt.figure()
ax = fig.add_subplot(121, projection='3d')
surf = ax.plot_surface(X, Y, Z, cmap=cm.jet)
plt.title(r'$\Psi = \frac{\Gamma}{2 \pi} \ln r$')
plt.xlabel('x')
plt.ylabel('y')
ax.view_init(35, 140)

ax = fig.add_subplot(122, projection='3d')
surf = ax.plot_surface(X, Y, Z2, rstride=1, cstride=1, cmap=cm.jet)
plt.title(r'$\Phi = -\frac{\Gamma}{2 \pi} \theta$')
plt.xlabel('x')
plt.ylabel('y')
ax.view_init(90, 0)
plt.show()
# Vortex Flow interactive chart

def vortexPlot(C, C2, Gamma):
    # Set freestream velocity
    Vinf = 1 # (units: m/s)
    plt.rcParams["figure.figsize"] = (10,8)
    # Set range
    xr = 10
    xl = -xr
    yu = 10
    yl = -yu
       
    # Set x, y  points
    npoints = 100
    x = np.linspace(xl, xr, npoints)
    y = np.linspace(yl, yu, npoints)
    X, Y = np.meshgrid(x, y)
    
    
    Z = (Gamma)/(2 * np.pi) * np.log( np.sqrt(np.power(X,2) + np.power(Y,2)) )
    CS = plt.contour(X, Y, Z, levels=[C])
    fmt='%1.4f'
    plt.clabel(CS, inline=1, fontsize=11, fmt=fmt)
    

    Z = -(Gamma)/(2 * np.pi) * np.arctan(Y/X)
    CS2 = plt.contour(X, Y, Z, levels=[C2], colors='k',linestyles='dashed')
    plt.clabel(CS2, inline=1, fontsize=11, fmt=fmt)
    
    plt.title(r'$\Psi = \frac{\Gamma}{2 \pi} \ln r$   and   $\Phi = -\frac{\Gamma}{2 \pi} \theta$')
    plt.xlabel('x')
    plt.ylabel('y')
    plt.tight_layout()
    plt.show()
    
interactive_plot = interactive(vortexPlot, C=widgets.FloatSlider(value=0.006,min=-0.01,max=0.01,step=0.00025,description='$\Psi$'), C2=widgets.FloatSlider(value=0.001,min=-0.01,max=0.01,step=0.00025,description='$\Phi$'), Gamma=widgets.FloatSlider(value=0.03,min=0.01,max=0.1,step=0.01,description='$\Gamma$'));
interactive_plot.children[0].layout.height = '30px'
interactive_plot.children[0].layout.width = '500px'
interactive_plot.children[0].readout_format = '.4f'
interactive_plot.children[1].layout.height = '30px'
interactive_plot.children[1].layout.width = '500px'
interactive_plot.children[1].readout_format = '.4f'
interactive_plot.children[2].layout.height = '30px'
interactive_plot.children[2].layout.width = '500px'
interactive_plot.children[2].readout_format = '.4f'
interactive_plot
#print(interactive_plot.children[1].keys)
 
$$\text{Doublet Flow}$$$$\Psi = -\frac{\kappa}{2 \pi} \frac{sin\theta}{r} \\$$$$\Phi = \frac{\kappa}{2 \pi} \frac{cos\theta}{r} $$
# Doublet Flow

# Set range
xr = 10
xl = -xr

yu = 10
yl = -yu

npoints = 100
x = np.linspace(xl, xr, npoints)
y = np.linspace(yl, yu, npoints)

X, Y = np.meshgrid(x, y)

Kappa = 0.02

plt.rcParams["figure.figsize"] = (18,9)


plt.subplot(1,2,1)
Z = -Y*((Kappa)/(2 * np.pi))/(np.power(X,2) + np.power(Y,2)) 
levels = np.linspace(np.min(Z),np.max(Z),101)
CS = plt.contour(X, Y, Z, levels=levels)
fmt='%1.6f'
plt.clabel(CS, inline=1, fontsize=11,fmt=fmt)
plt.title(r'$\Psi = -\frac{\kappa}{2 \pi} \frac{sin\theta}{r}$')
plt.xlabel('$x$')
plt.ylabel('$y$')


plt.subplot(1,2,2)
Z = X*((Kappa)/(2 * np.pi))/(np.power(X,2) + np.power(Y,2)) 
CS = plt.contour(X, Y, Z, levels=levels)
plt.clabel(CS, inline=1, fontsize=11, fmt=fmt)




#plt.axis('equal','box')
#plt.title('Simplest default with labels')
plt.title(r'$\Phi = \frac{\kappa}{2 \pi} \frac{cos\theta}{r}$')
plt.xlabel('$x$')
plt.ylabel('$y$')

plt.tight_layout()
plt.show
<function matplotlib.pyplot.show(*args, **kw)>
# Make data.
 # Set range
plt.rcParams["figure.figsize"] = (20,8)
xr = 10
xl = -xr
yu = 10
yl = -yu

# Set x, y  points
npoints = 100
x = np.linspace(xl, xr, npoints)
y = np.linspace(yl, yu, npoints)
X, Y = np.meshgrid(x, y) 

Vinf = 1
Kappa = 0.02
Z = -Y*((Kappa)/(2 * np.pi))/(np.power(X,2) + np.power(Y,2)) 
Z2 = X*((Kappa)/(2 * np.pi))/(np.power(X,2) + np.power(Y,2))

fig = plt.figure()
ax = fig.add_subplot(121, projection='3d')
surf = ax.plot_surface(X, Y, Z, cmap=cm.jet)
plt.title(r'$\Psi = -\frac{\kappa}{2 \pi} \frac{sin\theta}{r}$')
plt.xlabel('x')
plt.ylabel('y')
ax.view_init(20, 40)

ax = fig.add_subplot(122, projection='3d')
surf = ax.plot_surface(X, Y, Z2, rstride=1, cstride=1, cmap=cm.jet)
plt.title(r'$\Phi = \frac{\kappa}{2 \pi} \frac{cos\theta}{r}$')
plt.xlabel('x')
plt.ylabel('y')
ax.view_init(20, 45)
plt.show()
# Doublet Flow interactive chart

def doubletPlot(C, C2, Kappa):
    # Set freestream velocity
    Vinf = 1 # (units: m/s)
    plt.rcParams["figure.figsize"] = (10,8)
    # Set range
    xr = 10
    xl = -xr
    yu = 10
    yl = -yu
       
    # Set x, y  points
    npoints = 100
    x = np.linspace(xl, xr, npoints)
    y = np.linspace(yl, yu, npoints)
    X, Y = np.meshgrid(x, y)
    
    
    Z = -Y*((Kappa)/(2 * np.pi))/(np.power(X,2) + np.power(Y,2))
    CS = plt.contour(X, Y, Z, levels=[C])
    fmt='%1.5f'
    plt.clabel(CS, inline=1, fontsize=11, fmt=fmt)
    

    Z = X*((Kappa)/(2 * np.pi))/(np.power(X,2) + np.power(Y,2)) 
    CS2 = plt.contour(X, Y, Z, levels=[C2], colors='k',linestyles='dashed')
    plt.clabel(CS2, inline=1, fontsize=11, fmt=fmt)
    
    plt.title(r'$\Psi = -\frac{\kappa}{2 \pi} \frac{sin\theta}{r}$   and   $\Phi = \frac{\kappa}{2 \pi} \frac{cos\theta}{r}$')
    plt.xlabel('x')
    plt.ylabel('y')
    plt.tight_layout()
    plt.show()
    
interactive_plot = interactive(doubletPlot, C=widgets.FloatSlider(value=0.0003,min=-0.04,max=0.04,step=0.0001,description='$\Psi$'), C2=widgets.FloatSlider(value=0.0003,min=-0.04,max=0.04,step=0.0001,description='$\Phi$'), Kappa=widgets.FloatSlider(value=0.0156,min=0.0001,max=0.1,step=0.00025,description='$\kappa$'));
interactive_plot.children[0].layout.height = '30px'
interactive_plot.children[0].layout.width = '500px'
interactive_plot.children[0].readout_format = '.4f'
interactive_plot.children[1].layout.height = '30px'
interactive_plot.children[1].layout.width = '500px'
interactive_plot.children[1].readout_format = '.4f'
interactive_plot.children[2].layout.height = '30px'
interactive_plot.children[2].layout.width = '500px'
interactive_plot.children[2].readout_format = '.4f'
interactive_plot
#print(interactive_plot.children[1].keys)
 
$$\text{Superposition of uniform Flow and source Flow}$$$$\Psi = V_\infty y + \frac{\Lambda}{2 \pi} \theta\\$$$$\Phi = V_\infty x + \frac{\Lambda}{2 \pi} \ln r $$
# Uniform Flow + Source

# Set freestream velocity
#Lambda = 2 * np.pi #  Set for convenience

Lambda = 8
Vinf = 1

plt.rcParams["figure.figsize"] = (18,9)


yu = 10;
yl = -yu

xl = -5
xr = 5

# Set x, y  points
npoints = 200
x = np.linspace(xl, xr, npoints*2)
y = np.linspace(yl, yu, npoints)

X, Y = np.meshgrid(x, y)

# Psi
plt.subplot(1,2,1)

Z = Vinf * Y + (Lambda)/(2 * np.pi) * np.arctan2(Y,X)
levels = np.linspace(np.min(Z),np.max(Z),41)
CS = plt.contour(X, Y, Z, levels=levels)
plt.clabel(CS, inline=1, fontsize=11)

plt.title(r'$\Psi = V_\infty y + \frac{\Lambda}{2 \pi} \theta$')
plt.xlabel('$x$')
plt.ylabel('$y$')
plt.grid()

#Phi
plt.subplot(1,2,2)
Z = Vinf * X + (Lambda)/(2 * np.pi) * np.log( np.sqrt(np.power(X,2) + np.power(Y,2)) )

#plt.contour(Z,np.linspace(Z.min(),Z.max(),15))
#levels = np.linspace(np.min(Z),0.0035,11)
levels = np.linspace(np.min(Z),np.max(Z),41)

CS = plt.contour(X, Y, Z, levels=levels)
#CS = plt.contour(X, Y, Z)
plt.clabel(CS, inline=1, fontsize=11)


plt.title(r'$\Phi = V_\infty x + \frac{\Lambda}{2 \pi} \ln r $')
plt.xlabel('$x$')
plt.ylabel('$y$')


plt.tight_layout()
plt.show
<function matplotlib.pyplot.show(*args, **kw)>
# Make data.
 # Set range
plt.rcParams["figure.figsize"] = (20,8)
xr = 5
xl = -xr
yu = 5
yl = -yu

# Set x, y  points
npoints = 100
x = np.linspace(xl, xr, npoints)
y = np.linspace(yl, yu, npoints)
X, Y = np.meshgrid(x, y) 

Vinf = 1
Lambda = 8
Z = Vinf * Y + (Lambda)/(2 * np.pi) * np.arctan2(Y,X)
Z2 = Vinf * X + (Lambda)/(2 * np.pi) * np.log( np.sqrt(np.power(X,2) + np.power(Y,2)) )

fig = plt.figure()
ax = fig.add_subplot(121, projection='3d')
surf = ax.plot_surface(X, Y, Z, cmap=cm.jet)
plt.title(r'$\Psi = V_\infty y + \frac{\Lambda}{2 \pi} \theta$')
plt.xlabel('x')
plt.ylabel('y')
ax.view_init(0, -40)

ax = fig.add_subplot(122, projection='3d')
surf = ax.plot_surface(X, Y, Z2, rstride=1, cstride=1, cmap=cm.jet)
plt.title(r'$\Phi = V_\infty x + \frac{\Lambda}{2 \pi} \ln r $')
plt.xlabel('x')
plt.ylabel('y')
ax.view_init(15, 90)
plt.show()
# Superposition of uniform Flow and source Flow interactive chart

def uniformAndSourcePlot(C, C2, Lambda):
    # Set freestream velocity
    Vinf = 1 # (units: m/s)
    plt.rcParams["figure.figsize"] = (10,8)
    # Set range
    xr = 10
    xl = -xr
    yu = 10
    yl = -yu
       
    # Set x, y  points
    npoints = 100
    x = np.linspace(xl, xr, npoints)
    y = np.linspace(yl, yu, npoints)
    X, Y = np.meshgrid(x, y)
    
    
    Z = Vinf * Y + (Lambda)/(2 * np.pi) * np.arctan2(Y,X)
    CS = plt.contour(X, Y, Z, levels=[C])
    fmt='%1.4f'
    plt.clabel(CS, inline=1, fontsize=11, fmt=fmt)
    

    Z = Vinf * X + (Lambda)/(2 * np.pi) * np.log( np.sqrt(np.power(X,2) + np.power(Y,2)) )
    CS2 = plt.contour(X, Y, Z, levels=[C2], colors='k',linestyles='dashed')
    plt.clabel(CS2, inline=1, fontsize=11, fmt=fmt)
    
    plt.title(r'$\Psi = V_\infty y + \frac{\Lambda}{2 \pi} \theta$   and   $\Phi = V_\infty x + \frac{\Lambda}{2 \pi} \ln r $')
    plt.xlabel('x')
    plt.ylabel('y')
    plt.tight_layout()
    plt.show()
    
interactive_plot = interactive(uniformAndSourcePlot, C=widgets.FloatSlider(value=1,min=-10,max=10,step=0.2,description='$\Psi$'), C2=widgets.FloatSlider(value=-0.8,min=-10,max=10,step=0.2,description='$\Phi$'), Lambda=widgets.FloatSlider(value=8,min=0.5,max=10,step=0.5,description='$\Lambda$'));
interactive_plot.children[0].layout.height = '30px'
interactive_plot.children[0].layout.width = '500px'
interactive_plot.children[0].readout_format = '.4f'
interactive_plot.children[1].layout.height = '30px'
interactive_plot.children[1].layout.width = '500px'
interactive_plot.children[1].readout_format = '.4f'
interactive_plot.children[2].layout.height = '30px'
interactive_plot.children[2].layout.width = '500px'
interactive_plot.children[2].readout_format = '.4f'
interactive_plot
#print(interactive_plot.children[1].keys)
 
$$\text{Rankine Oval}$$$$\Psi = V_\infty y + \frac{\Lambda}{2 \pi} (\theta_1-\theta_2)\\$$$$\Phi = V_\infty x + \frac{\Lambda}{2 \pi} (\ln r_1/r_2) $$
Lambda = 4
Vinf = 1

plt.rcParams["figure.figsize"] = (18,9)

xr = 4.5
xl = -xr

yu = 3;
yl = -yu


# Set x, y  points
npoints = 200
x = np.linspace(xl, xr, npoints*2)
y = np.linspace(yl, yu, npoints)

X, Y = np.meshgrid(x, y)

xloc = 1.5
# Psi
plt.subplot(1,2,1)
Z = Vinf * Y + (Lambda)/(2 * np.pi) * np.arctan2(Y,X + xloc) - (Lambda)/(2 * np.pi) * np.arctan2(Y,X - xloc)
#CS = plt.contour(X, Y, Z)
levels = np.linspace(np.min(Z),np.max(Z),35)
CS = plt.contour(X, Y, Z, levels=levels)
plt.clabel(CS, inline=1, fontsize=11)
#plt.axis('equal','box')
#plt.title('Simplest default with labels')
plt.title(r'$\Psi = V_\infty y + \frac{\Lambda}{2 \pi} (\theta_1-\theta_2)$')
plt.xlabel('$x$')
plt.ylabel('$y$')
#plt.xlim(-0.1, .1)
plt.grid()

#Phi
plt.subplot(1,2,2)

Z = Vinf * X + (Lambda)/(2 * np.pi) * np.log( np.sqrt(np.power(X + xloc,2) + np.power(Y,2)) ) - (Lambda)/(2 * np.pi) * np.log( np.sqrt(np.power(X - xloc,2) + np.power(Y,2)) )

#plt.contour(Z,np.linspace(Z.min(),Z.max(),15))
#levels = np.linspace(np.min(Z),0.0035,11)
levels = np.linspace(np.min(Z),np.max(Z),15)

CS = plt.contour(X, Y, Z, levels=levels)
#CS = plt.contour(X, Y, Z)
plt.clabel(CS, inline=1, fontsize=11)


plt.title(r'$\Phi = V_\infty x + \frac{\Lambda}{2 \pi} \ln (r_1/r_2) $')
plt.xlabel('$x$')
plt.ylabel('$y$')


plt.tight_layout()
plt.show
<function matplotlib.pyplot.show(*args, **kw)>
# Make data.
 # Set range
plt.rcParams["figure.figsize"] = (20,8)
xr = 4.5
xl = -xr
yu = 3
yl = -yu

# Set x, y  points
npoints = 100
x = np.linspace(xl, xr, npoints)
y = np.linspace(yl, yu, npoints)
X, Y = np.meshgrid(x, y) 

Vinf = 1
Lambda = 4
xloc = 1.5
Z = Vinf * Y + (Lambda)/(2 * np.pi) * np.arctan2(Y,X + xloc) - (Lambda)/(2 * np.pi) * np.arctan2(Y,X - xloc)
Z2 = Vinf * X + (Lambda)/(2 * np.pi) * np.log( np.sqrt(np.power(X + xloc,2) + np.power(Y,2)) ) - (Lambda)/(2 * np.pi) * np.log( np.sqrt(np.power(X - xloc,2) + np.power(Y,2)) )

fig = plt.figure()
ax = fig.add_subplot(121, projection='3d')
surf = ax.plot_surface(X, Y, Z, cmap=cm.jet)
plt.title(r'$\Psi = V_\infty y + \frac{\Lambda}{2 \pi} (\theta_1-\theta_2)$')
plt.xlabel('x')
plt.ylabel('y')
ax.view_init(30, 30)

ax = fig.add_subplot(122, projection='3d')
surf = ax.plot_surface(X, Y, Z2, rstride=1, cstride=1, cmap=cm.jet)
plt.title(r'$\Phi = V_\infty x + \frac{\Lambda}{2 \pi} \ln (r_1/r_2) $')
plt.xlabel('x')
plt.ylabel('y')
ax.view_init(15, 90)
plt.show()
# Rankine Oval interactive chart

def rankineOvalPlot(C, C2, Lambda,xloc):
    # Set freestream velocity
    Vinf = 1 # (units: m/s)
    plt.rcParams["figure.figsize"] = (10,8)
    # Set range
    xr = 10
    xl = -xr
    yu = 10
    yl = -yu
       
    # Set x, y  points
    npoints = 100
    x = np.linspace(xl, xr, npoints)
    y = np.linspace(yl, yu, npoints)
    X, Y = np.meshgrid(x, y)
    
    
    Z = Vinf * Y + (Lambda)/(2 * np.pi) * np.arctan2(Y,X + xloc) - (Lambda)/(2 * np.pi) * np.arctan2(Y,X - xloc)
    CS = plt.contour(X, Y, Z, levels=[C])
    fmt='%1.4f'
    plt.clabel(CS, inline=1, fontsize=11, fmt=fmt)
    

    Z = Vinf * X + (Lambda)/(2 * np.pi) * np.log( np.sqrt(np.power(X + xloc,2) + np.power(Y,2)) ) - (Lambda)/(2 * np.pi) * np.log( np.sqrt(np.power(X - xloc,2) + np.power(Y,2)) )
    CS2 = plt.contour(X, Y, Z, levels=[C2], colors='k',linestyles='dashed')
    plt.clabel(CS2, inline=1, fontsize=11, fmt=fmt)
    
    plt.title(r'$\Psi = V_\infty y + \frac{\Lambda}{2 \pi} (\theta_1-\theta_2)$   and   $\Phi = V_\infty x + \frac{\Lambda}{2 \pi} \ln (r_1/r_2) $')
    plt.xlabel('x')
    plt.ylabel('y')
    plt.tight_layout()
    plt.show()
    
interactive_plot = interactive(rankineOvalPlot, C=widgets.FloatSlider(value=0,min=-10,max=10,step=0.1,description='$\Psi$'), C2=widgets.FloatSlider(value=-3.2,min=-10,max=10,step=0.1,description='$\Phi$'), Lambda=widgets.FloatSlider(value=4,min=0.5,max=10,step=0.5,description='$\Lambda$'), xloc=widgets.FloatSlider(value=1.5,min=0.25,max=5,step=0.25,description='$xLoc$'));
interactive_plot.children[0].layout.height = '30px'
interactive_plot.children[0].layout.width = '500px'
interactive_plot.children[0].readout_format = '.4f'
interactive_plot.children[1].layout.height = '30px'
interactive_plot.children[1].layout.width = '500px'
interactive_plot.children[1].readout_format = '.4f'
interactive_plot.children[2].layout.height = '30px'
interactive_plot.children[2].layout.width = '500px'
interactive_plot.children[2].readout_format = '.4f'
interactive_plot.children[3].layout.height = '30px'
interactive_plot.children[3].layout.width = '500px'
interactive_plot.children[3].readout_format = '.4f'
interactive_plot
#print(interactive_plot.children[1].keys)
 
$$\text{Cylinder (Non-lifting flow)}$$$$\Psi = V_\infty y-\frac{\kappa}{2 \pi} \frac{sin\theta}{r} \\$$$$\Phi = V_\infty x + \frac{\kappa}{2 \pi} \frac{cos\theta}{r} $$
# Cylinder (Non-lifting flow)

# uniform  +  Doublet Flow
Vinf = 1

# Set range
xr = 5
xl = -xr

yu = 5
yl = -yu

npoints = 100
x = np.linspace(xl, xr, npoints)
y = np.linspace(yl, yu, npoints)

X, Y = np.meshgrid(x, y)

Kappa = 10

plt.rcParams["figure.figsize"] = (18,9)


plt.subplot(1,2,1)
Z = Vinf * Y - Y*((Kappa)/(2 * np.pi))/(np.power(X,2) + np.power(Y,2)) 
levels = np.linspace(np.min(Z),np.max(Z),61)
CS = plt.contour(X, Y, Z, levels=levels)
fmt='%1.4f'
plt.clabel(CS, inline=1, fontsize=11,fmt=fmt)
plt.title(r'$\Psi = V_\infty y-\frac{\kappa}{2 \pi} \frac{sin\theta}{r}$')
plt.xlabel('$x$')
plt.ylabel('$y$')


plt.subplot(1,2,2)
Z = Vinf * X + X*((Kappa)/(2 * np.pi))/(np.power(X,2) + np.power(Y,2)) 
levels = np.linspace(np.min(Z),np.max(Z),61)
CS = plt.contour(X, Y, Z, levels=levels)
plt.clabel(CS, inline=1, fontsize=11, fmt=fmt)




#plt.axis('equal','box')
#plt.title('Simplest default with labels')
plt.title(r'$\Phi = V_\infty x +\frac{\kappa}{2 \pi} \frac{cos\theta}{r}$')
plt.xlabel('$x$')
plt.ylabel('$y$')

plt.tight_layout()
plt.show
<function matplotlib.pyplot.show(*args, **kw)>
# Make data.
 # Set range
plt.rcParams["figure.figsize"] = (20,8)
xr = 5
xl = -xr
yu = 5
yl = -yu

# Set x, y  points
npoints = 100
x = np.linspace(xl, xr, npoints)
y = np.linspace(yl, yu, npoints)
X, Y = np.meshgrid(x, y) 

Vinf = 1
Kappa = 10
xloc = 1.5
Z = Vinf * Y - Y*((Kappa)/(2 * np.pi))/(np.power(X,2) + np.power(Y,2)) 
Z2 = Vinf * X + X*((Kappa)/(2 * np.pi))/(np.power(X,2) + np.power(Y,2)) 
fig = plt.figure()
ax = fig.add_subplot(121, projection='3d')
surf = ax.plot_surface(X, Y, Z, cmap=cm.jet)
plt.title(r'$\Psi = V_\infty y-\frac{\kappa}{2 \pi} \frac{sin\theta}{r}$')
plt.xlabel('x')
plt.ylabel('y')
ax.view_init(30, 70)

ax = fig.add_subplot(122, projection='3d')
surf = ax.plot_surface(X, Y, Z2, rstride=1, cstride=1, cmap=cm.jet)
plt.title(r'$\Phi = V_\infty x +\frac{\kappa}{2 \pi} \frac{cos\theta}{r}$')
plt.xlabel('x')
plt.ylabel('y')
ax.view_init(30, 70)
plt.show()
# Cylinder (Non-lifting flow) interactive chart

def cylinderNonLiftingPlot(C, C2, Kappa):
    # Set freestream velocity
    Vinf = 1 # (units: m/s)
    plt.rcParams["figure.figsize"] = (10,8)
    # Set range
    xr = 5
    xl = -xr
    yu = 5
    yl = -yu
       
    # Set x, y  points
    npoints = 100
    x = np.linspace(xl, xr, npoints)
    y = np.linspace(yl, yu, npoints)
    X, Y = np.meshgrid(x, y)
    
    
    Z = Vinf * Y - Y*((Kappa)/(2 * np.pi))/(np.power(X,2) + np.power(Y,2))
    CS = plt.contour(X, Y, Z, levels=[C])
    fmt='%1.5f'
    plt.clabel(CS, inline=1, fontsize=11, fmt=fmt)
    

    Z = Vinf * X + X*((Kappa)/(2 * np.pi))/(np.power(X,2) + np.power(Y,2)) 
    CS2 = plt.contour(X, Y, Z, levels=[C2], colors='k',linestyles='dashed')
    plt.clabel(CS2, inline=1, fontsize=11, fmt=fmt)
    
    plt.title(r'$\Psi = V_\infty y-\frac{\kappa}{2 \pi} \frac{sin\theta}{r}$   and   $\Phi = V_\infty x+\frac{\kappa}{2 \pi} \frac{cos\theta}{r}$')
    plt.xlabel('x')
    plt.ylabel('y')
    plt.tight_layout()
    plt.show()
    
interactive_plot = interactive(cylinderNonLiftingPlot, C=widgets.FloatSlider(value=0,min=-5,max=5,step=0.1,description='$\Psi$'), C2=widgets.FloatSlider(value=-3,min=-5,max=5,step=0.1,description='$\Phi$'), Kappa=widgets.FloatSlider(value=32,min=0,max=60,step=4,description='$\kappa$'));
interactive_plot.children[0].layout.height = '30px'
interactive_plot.children[0].layout.width = '500px'
interactive_plot.children[0].readout_format = '.4f'
interactive_plot.children[1].layout.height = '30px'
interactive_plot.children[1].layout.width = '500px'
interactive_plot.children[1].readout_format = '.4f'
interactive_plot.children[2].layout.height = '30px'
interactive_plot.children[2].layout.width = '500px'
interactive_plot.children[2].readout_format = '.4f'
interactive_plot
#print(interactive_plot.children[1].keys)
 
$$\text{Cylinder (lifting flow)}$$$$\Psi = V_\infty y-\frac{\kappa}{2 \pi} \frac{sin\theta}{r} + \frac{\Gamma}{2 \pi} \ln r \\$$$$\Phi = V_\infty x + \frac{\kappa}{2 \pi} \frac{cos\theta}{r}-\frac{\Gamma}{2 \pi} \theta $$
# Cylinder (Lifting flow)


# uniform  +  Doublet Flow
Vinf = 1

# Set range
xr = 5
xl = -xr

yu = 5
yl = -yu

npoints = 100
x = np.linspace(xl, xr, npoints)
y = np.linspace(yl, yu, npoints)

X, Y = np.meshgrid(x, y)

Kappa = 10
Gamma = 5

plt.rcParams["figure.figsize"] = (18,9)


plt.subplot(1,2,1)
Z = Vinf * Y - Y*((Kappa)/(2 * np.pi))/(np.power(X,2) + np.power(Y,2)) + (Gamma)/(2 * np.pi) * np.log( np.sqrt(np.power(X,2) + np.power(Y,2)) ) 
levels = np.linspace(np.min(Z),np.max(Z),61)
CS = plt.contour(X, Y, Z, levels=levels)
fmt='%1.4f'
plt.clabel(CS, inline=1, fontsize=11,fmt=fmt)
plt.title(r'$\Psi = V_\infty y-\frac{\kappa}{2 \pi} \frac{sin\theta}{r}+\frac{\Gamma}{2 \pi} \ln r$')
plt.xlabel('$x$')
plt.ylabel('$y$')


plt.subplot(1,2,2)
Z = Vinf * X + X*((Kappa)/(2 * np.pi))/(np.power(X,2) + np.power(Y,2)) - (Gamma)/(2 * np.pi) * np.arctan(Y/X) 
levels = np.linspace(np.min(Z),np.max(Z),61)
CS = plt.contour(X, Y, Z, levels=levels)
plt.clabel(CS, inline=1, fontsize=11, fmt=fmt)




#plt.axis('equal','box')
#plt.title('Simplest default with labels')
plt.title(r'$\Phi = V_\infty x +\frac{\kappa}{2 \pi} \frac{cos\theta}{r}-\frac{\Gamma}{2 \pi} \theta$')
plt.xlabel('$x$')
plt.ylabel('$y$')

plt.tight_layout()
plt.show
<function matplotlib.pyplot.show(*args, **kw)>
# Make data.
 # Set range
plt.rcParams["figure.figsize"] = (20,8)
xr = 5
xl = -xr
yu = 5
yl = -yu

# Set x, y  points
npoints = 100
x = np.linspace(xl, xr, npoints)
y = np.linspace(yl, yu, npoints)
X, Y = np.meshgrid(x, y) 

Vinf = 1
Kappa = 10
Gamma = 5
Z = Vinf * Y - Y*((Kappa)/(2 * np.pi))/(np.power(X,2) + np.power(Y,2)) + (Gamma)/(2 * np.pi) * np.log( np.sqrt(np.power(X,2) + np.power(Y,2)) ) 
Z2 = Vinf * X + X*((Kappa)/(2 * np.pi))/(np.power(X,2) + np.power(Y,2)) - (Gamma)/(2 * np.pi) * np.arctan(Y/X) 
fig = plt.figure()
ax = fig.add_subplot(121, projection='3d')
surf = ax.plot_surface(X, Y, Z, cmap=cm.jet)
plt.title(r'$\Psi = V_\infty y-\frac{\kappa}{2 \pi} \frac{sin\theta}{r}+\frac{\Gamma}{2 \pi} \ln r$')
plt.xlabel('x')
plt.ylabel('y')
ax.view_init(30, 70)

ax = fig.add_subplot(122, projection='3d')
surf = ax.plot_surface(X, Y, Z2, rstride=1, cstride=1, cmap=cm.jet)
plt.title(r'$\Phi = V_\infty x +\frac{\kappa}{2 \pi} \frac{cos\theta}{r}-\frac{\Gamma}{2 \pi} \theta$')
plt.xlabel('x')
plt.ylabel('y')
ax.view_init(30, 70)
plt.show()
# Cylinder (lifting flow) interactive chart

def cylinderLiftingPlot(C, C2, Kappa, Gamma):
    # Set freestream velocity
    Vinf = 1 # (units: m/s)
    plt.rcParams["figure.figsize"] = (10,8)
    # Set range
    xr = 5
    xl = -xr
    yu = 5
    yl = -yu
       
    # Set x, y  points
    npoints = 100
    x = np.linspace(xl, xr, npoints)
    y = np.linspace(yl, yu, npoints)
    X, Y = np.meshgrid(x, y)
    
    
    Z = Vinf * Y - Y*((Kappa)/(2 * np.pi))/(np.power(X,2) + np.power(Y,2)) + (Gamma)/(2 * np.pi) * np.log( np.sqrt(np.power(X,2) + np.power(Y,2)) ) 
    CS = plt.contour(X, Y, Z, levels=[C])
    fmt='%1.5f'
    plt.clabel(CS, inline=1, fontsize=11, fmt=fmt)
    

    Z = Vinf * X + X*((Kappa)/(2 * np.pi))/(np.power(X,2) + np.power(Y,2)) - (Gamma)/(2 * np.pi) * np.arctan(Y/X)  
    CS2 = plt.contour(X, Y, Z, levels=[C2], colors='k',linestyles='dashed')
    plt.clabel(CS2, inline=1, fontsize=11, fmt=fmt)
    
    plt.title(r'$\Psi = V_\infty y -\frac{\kappa}{2 \pi} \frac{sin\theta}{r}+\frac{\Gamma}{2 \pi} \ln r$   and   $\Phi = V_\infty x +\frac{\kappa}{2 \pi} \frac{cos\theta}{r}-\frac{\Gamma}{2 \pi} \theta$')
    plt.xlabel('x')
    plt.ylabel('y')
    plt.tight_layout()
    plt.show()
    
interactive_plot = interactive(cylinderLiftingPlot, C=widgets.FloatSlider(value=0,min=-5,max=5,step=0.1,description='$\Psi$'), C2=widgets.FloatSlider(value=-3,min=-5,max=5,step=0.1,description='$\Phi$'), Kappa=widgets.FloatSlider(value=32,min=0,max=60,step=2,description='$\kappa$'), Gamma=widgets.FloatSlider(value=1,min=0,max=30,step=1,description='$\Gamma$'));
interactive_plot.children[0].layout.height = '30px'
interactive_plot.children[0].layout.width = '500px'
interactive_plot.children[0].readout_format = '.4f'
interactive_plot.children[1].layout.height = '30px'
interactive_plot.children[1].layout.width = '500px'
interactive_plot.children[1].readout_format = '.4f'
interactive_plot.children[2].layout.height = '30px'
interactive_plot.children[2].layout.width = '500px'
interactive_plot.children[2].readout_format = '.4f'
interactive_plot.children[3].layout.height = '30px'
interactive_plot.children[3].layout.width = '500px'
interactive_plot.children[3].readout_format = '.4f'
interactive_plot
#print(interactive_plot.children[1].keys)